"""对时间进行处理"""
import time


def time2chinese(timestamp):
    # 对长度进行限制
    timestamp = int(str(timestamp)[:10])
    now_time = time.time()
    time_diff = int(now_time - timestamp)
    if time_diff < 0:
        word = 'None'
    elif time_diff < 60:
        word = f'{time_diff}秒前'
    elif 60 <= time_diff < 3600:
        word = f'{time_diff // 60}分钟前'
    elif 3600 <= time_diff < 86400:
        word = f'{time_diff // 3600}小时前'
    elif 86400 <= time_diff < 259200:
        word = f'{time_diff // 86400}天前'
    else:
        time_array = time.localtime(timestamp)  # 转换为可用的时间，就是下面的%Y %m %d
        day_time = time.strftime('%Y/%m/%d', time_array)  # 取上面的timeArray中的对应值0
        word = f'{day_time}'
    return word